package com.example.demo.shengcheng;

import com.example.demo.mapper.LifebookMapper;
import com.example.demo.pojo.Lifebook;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;


@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class Mainadd {
    static Random random = new Random();
    static LocalDate now = LocalDate.now();
    static Calendar calendar = Calendar.getInstance();
    static Date date = new Date();
    static SimpleDateFormat f = new SimpleDateFormat(" HH:mm:ss");

    @Autowired
    LifebookMapper mapper;
    @Test
  public void testleftbook(){
        for (int i = 1; i < 90; i++) {
            try{
                Lifebook lifebook = lifebook(i);
//                System.out.println(lifebook);
                mapper.addLifeBook(lifebook);
            }catch (Exception e){
                continue;
            }

        }

    }






    public  Lifebook lifebook(int n){
        // 生成姓名
//        String[] kkk=NameGenerator.generateNames(NameGenerator.MALE_FIRST_NAMES, NameGenerator.FEMALE_FIRST_NAMES, 1);
//        String name = kkk[0];
        String s = name生成.numberToChinese(n);
        String name="猴"+s;
        // 生成uuid
        String uuid = UUID.randomUUID().toString().replace("-", "");
        // 生成出生日期
        int i = random.nextInt(150);
        LocalDate localDate = now.minusYears(i).minusMonths(i).minusDays(i);
        String format = f.format(date);
        String birthday = localDate.toString() + format;
        // 生成死亡日期
        int i1 = random.nextInt(101);
        String deathday=null;
        while (true){
            if (i>i1) {
                LocalDate localDate1 = now.minusYears(i1).minusMonths(i1).minusDays(i1);
                deathday = localDate1.toString() + f.format(date);
                break;
            }else {
                 i1 = random.nextInt(101);
            }
        }
        // 生成生成八字
        String shi = format.substring(1, 3);
        String fen = format.substring(4,6);
        calendar.set(localDate.getYear(),localDate.getMonthValue()-1,localDate.getDayOfMonth(),Integer.parseInt(shi),Integer.parseInt(fen));
        String year = scbz.getBazi(calendar);
        // 状态，0表示未出生，1在世，2在地府生活，3轮回中，4受刑中
        int status=0;

        // 生成性别
        int gender = random.nextInt(2);
        // 生成出生地址
        String birthplace = AddressGenerator.getRandomAddress();
        // 生成死亡地址
        String deathplace = AddressGenerator.getRandomAddressWithMatch(birthplace);
        // 照片
        String photo="https://web-shujia.oss-cn-chengdu.aliyuncs.com/2af62d8c-356e-4e22-b34c-728e1d585d64.jpg";
//        if (gender==0){
//            photo="https://web-shujia.oss-cn-chengdu.aliyuncs.com/4bf0bf78-6b01-4d8a-80e5-ef9ab113a87e.jpg";
//        }else{
//            photo="https://web-shujia.oss-cn-chengdu.aliyuncs.com/89fa342b-a0fe-4748-ba2c-525761aa6f7a.png";
//        }

        // 命中财的数量
        Integer money=random.nextInt(100000000);
        // 死后阴财的数量
        Integer yinmoney=random.nextInt(100000000);
        // 命中子的数量
        Integer child=0;
        if (i>17){
            child=random.nextInt(2);
        }
        if (i>28)child=random.nextInt(4);
        // 寿元
        int longevity=i;
        // 死亡类型
        int type=i>75?0:1;
        // 死因
        String reason=Deltype.siwang(type);
        // 婚配情况
        String marriage = i<22?"未婚":"已婚";
        // 人生大事描述
        String event="过于复杂暂不生成";
        // 人物属性
        double v = random.nextDouble();
        String attribute=0.5<=v?"好人":"坏人";
        // 人生描述
        List descr = Description.descr(v, reason);
        String description= descr.get(descr.size()-1).toString();
        // 人物描述
        String characterinfo=Description.characterinfo(descr);
        // 阴德
        int yin = Gongei.yin(v);
        // 阳德
        int yang = Gongei.yang(v);
        // 奖赏情况
        String reward="暂无";
        // 死后情况
        String afterlife="未出生";
        // 轮回情况
        String reincarnation= "在世";
        //受刑情况
        String punishment=null;
        // 勾魂操作者id
        Integer reaperid=null;
        // 审判操作者id
        Integer judgeid= null;
        // 受刑id
        Integer punishmentid=null;
        // 轮回盘id
        Integer reincarnationid=null;
        LocalDateTime create_time=null;
        return new Lifebook(name,uuid,year,status,birthday,deathday,gender,birthplace,deathplace,photo,
                money,yinmoney,child,longevity,type,reason,marriage,event,attribute,description,
                characterinfo,yin,yang,reward,afterlife,reincarnation,punishment,reaperid,judgeid,punishmentid,
                reincarnationid,create_time);
//        return null;
    }
}
